<template>
  <div class="control-item">
    <div class="control-header">
      <span class="control-name">搜索</span>
      <span @click="showBeautyBox = true">组件美化</span>
    </div>
    <div class="control-body">
      <div class="control-section">
        <div class="control-item">
          <div class="control-title">模板样式</div>
          <div class="control-content">
            <div class="example-list">
              <div
                class="example-item"
                v-for="(item, index) in exampleList"
                :key="index"
                @click="setStyleType(item)"
                :class="styleType == item.value ? 'active' : ''"
              >
                <i class="iconfont" :class="item.icon" />
              </div>
            </div>
          </div>
        </div>
        <!-- 边角样式 -->
        <div class="control-item" v-show="styleType != 2">
          <div class="control-title flex-between">
            <span>边角样式</span>
            <span class="reset" @click="resetItem('border')">重置</span>
          </div>
          <div class="control-content">
            <a-select
              :default-value="params.params.borderType"
              @change="setControlItem"
              class="border-select"
            >
              <a-select-option value="1"> 圆角 </a-select-option>
              <a-select-option value="2"> 直角 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 常驻顶部 -->
        <div class="control-item">
          <div class="control-title flex-between">
            <span>常驻顶部</span>
            <span class="reset" @click="resetItem('fixedTop')">重置</span>
          </div>
          <div class="control-content">
            <a-select
              :default-value="params.params.fixedTop"
              @change="setFixedTop"
              class="fixed-top-select"
            >
              <a-select-option :value="0"> 关闭 </a-select-option>
              <a-select-option :value="1"> 开启 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 热门搜索词 -->
        <div class="control-item">
          <div class="control-title flex-between">
            <span>热门搜索词</span>
            <span class="reset" @click="resetItem('placeholder')">重置</span>
          </div>
          <div class="control-content">
            <div class="keyword-input">
              <a-input
                placeholder="请输入搜索关键词"
                v-model="params.params.placeholder"
              />
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 组件美化 -->
    <comBeautyBox
      :showBeautyBox="showBeautyBox"
      @handleBack="showBeautyBox = false"
    >
      <div>
        <!-- 背景配置 -->
        <bgControl
          :backgroudData="params.moduleCss"
          sizeText="750*84"
        ></bgControl>
        <!-- 内容位置 -->
        <div class="com-beauty-item">
          <div
            class="beauty-item-header"
            @click.stop="showContentAlign = !showContentAlign"
          >
            <span>内容位置</span>
            <div class="header-action">
              <i
                v-if="params.params.contentAlign"
                class="iconfont icon-xianshi"
                @click.stop="$set(params.params, 'contentAlign', '')"
              ></i>
              <i
                v-else
                class="iconfont icon-yincang"
                @click.stop="$set(params.params, 'contentAlign', 'flex-start')"
              ></i>

              <i
                v-if="!showContentAlign"
                @click.stop="showContentAlign = !showContentAlign"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="showContentAlign = !showContentAlign"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <div class="beauty-item-body" v-if="showContentAlign">
            <a-select
              v-model="params.params.contentAlign"
              @change="setContentAlign"
              class="border-select"
            >
              <a-select-option value="flex-start"> 左对齐 </a-select-option>
              <a-select-option value="center"> 居中 </a-select-option>
            </a-select>
          </div>
        </div>
        <!-- 框体背景 -->
        <div class="com-beauty-item">
          <div
            class="beauty-item-header"
            @click.stop="showInputBgColor = !showInputBgColor"
          >
            <span>框体背景</span>
            <div class="header-action">
              <i
                v-if="params.params.inputBgColor"
                class="iconfont icon-xianshi"
                @click.stop="$set(params.params, 'inputBgColor', '')"
              ></i>
              <i
                v-else
                class="iconfont icon-yincang"
                @click.stop="$set(params.params, 'inputBgColor', '#F2F2F2')"
              ></i>

              <i
                v-if="!showInputBgColor"
                @click.stop="showInputBgColor = !showInputBgColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="showInputBgColor = !showInputBgColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <div class="beauty-item-body" v-if="showInputBgColor">
            <div class="color-set">
              <a-input
                type="color"
                :value="params.params.inputBgColor"
                @change="
                  (e) => {
                    $set(params.params, 'inputBgColor', e.target.value);
                  }
                "
              />
              <a-input
                type="text"
                :value="params.params.inputBgColor"
                @change="
                  (e) => {
                    $set(params.params, 'inputBgColor', e.target.value);
                  }
                "
              />
            </div>
          </div>
        </div>
        <!-- 框体描边 -->
        <div class="com-beauty-item">
          <div
            class="beauty-item-header"
            @click.stop="showInputBorder = !showInputBorder"
          >
            <span>框体描边</span>
            <div class="header-action">
              <i
                v-if="params.params.inputBorder"
                class="iconfont icon-xianshi"
                @click.stop="$set(params.params, 'inputBorder', '')"
              ></i>
              <i
                v-else
                class="iconfont icon-yincang"
                @click.stop="$set(params.params, 'inputBorder', '#707070')"
              ></i>

              <i
                v-if="!showInputBorder"
                @click.stop="showInputBorder = !showInputBorder"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="showInputBorder = !showInputBorder"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <div class="beauty-item-body" v-if="showInputBorder">
            <div class="color-set">
              <a-input
                type="color"
                :value="params.params.inputBorder"
                @change="
                  (e) => {
                    $set(params.params, 'inputBorder', e.target.value);
                  }
                "
              />
              <a-input
                type="text"
                :value="params.params.inputBorder"
                @change="
                  (e) => {
                    $set(params.params, 'inputBorder', e.target.value);
                  }
                "
              />
            </div>
          </div>
        </div>
        <!-- 内容颜色 -->
        <div class="com-beauty-item">
          <div
            class="beauty-item-header"
            @click.stop="showInputTextColor = !showInputTextColor"
          >
            <span>内容颜色</span>
            <div class="header-action">
              <i
                v-if="params.params.inputTextColor"
                class="iconfont icon-xianshi"
                @click.stop="$set(params.params, 'inputTextColor', '')"
              ></i>
              <i
                v-else
                class="iconfont icon-yincang"
                @click.stop="$set(params.params, 'inputTextColor', '#707070')"
              ></i>

              <i
                v-if="!showInputTextColor"
                @click.stop="showInputTextColor = !showInputTextColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="showInputTextColor = !showInputTextColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <div class="beauty-item-body" v-if="showInputTextColor">
            <div class="color-set">
              <a-input
                type="color"
                :value="params.params.inputTextColor"
                @change="
                  (e) => {
                    $set(params.params, 'inputTextColor', e.target.value);
                  }
                "
              />
              <a-input
                type="text"
                :value="params.params.inputTextColor"
                @change="
                  (e) => {
                    $set(params.params, 'inputTextColor', e.target.value);
                  }
                "
              />
            </div>
          </div>
        </div>
        <!-- 按钮颜色 -->
        <div class="com-beauty-item" v-if="styleType == 2">
          <div
            class="beauty-item-header"
            @click.stop="showSearchBtnColor = !showSearchBtnColor"
          >
            <span>按钮颜色</span>
            <div class="header-action">
              <i
                v-if="params.params.searchBtnColor"
                class="iconfont icon-xianshi"
                @click.stop.stop="$set(params.params, 'searchBtnColor', '')"
              ></i>
              <i
                v-else
                class="iconfont icon-yincang"
                @click.stop="$set(params.params, 'searchBtnColor', '#FA2C1B')"
              ></i>

              <i
                v-if="!showSearchBtnColor"
                @click.stop="showSearchBtnColor = !showSearchBtnColor"
                class="iconfont icon-jiahao"
              ></i>
              <i
                v-else
                @click.stop="showSearchBtnColor = !showSearchBtnColor"
                class="iconfont icon-jian"
              ></i>
            </div>
          </div>
          <div class="beauty-item-body" v-if="showSearchBtnColor">
            <div class="color-set">
              <a-input
                type="color"
                :value="params.params.searchBtnColor"
                @change="
                  (e) => {
                    $set(params.params, 'searchBtnColor', e.target.value);
                  }
                "
              />
              <a-input
                type="text"
                :value="params.params.searchBtnColor"
                @change="
                  (e) => {
                    $set(params.params, 'searchBtnColor', e.target.value);
                  }
                "
              />
            </div>
          </div>
        </div>
        <!-- 间距控制组件 -->
        <spaceControl
          :spaceData.sync="params.moduleCss"
          @resetSpace="resetSpace"
          @resetMp="resetMp"
        ></spaceControl>
      </div>
    </comBeautyBox>
  </div>
</template>

<script>
import bgControl from "@/components/DiyNew/diy/baseControl/bgControl/index.vue";
import spaceControl from "@/components/DiyNew/diy/baseControl/spaceControl/index.vue";
import comBeautyBox from "@/components/DiyNew/diy/comBeautyBox/comBeautyBox.vue";

export default {
  name: "diySearchControl",
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  components: {
    bgControl,
    spaceControl,
    comBeautyBox,
  },
  data() {
    return {
      borderType: "1",
      fixedTop: 0,
      exampleList: [
        {
          icon: "icon-changguisousuo",
          type: "模板1",
          value: "1",
        },
        {
          icon: "icon-anniusousuo",
          type: "模板2",
          value: "2",
        },
      ],
      showBeautyBox: false,
      showContentAlign: false,
      showInputBgColor: false,
      showInputBorder: false,
      showInputTextColor: false,
      showSearchBtnColor: false,
    };
  },
  watch: {},
  mounted() {},

  computed: {
    styleType: {
      get() {
        return this.params.params.styleType || "1";
      },
    },
  },
  methods: {
    // 点击重置
    resetItem(type) {
      console.log(type);
      if (type == "border") {
        this.$set(this.params.params, "borderType", "1");
      }
      if (type == "fixedTop") {
        this.$set(this.params.params, "fixedTop", 0);
      }
      if (type == "placeholder") {
        this.$set(this.params.params, "placeholder", "");
      }
    },
    resetFontCss() {
      console.log("重置数据");
      this.$set(this.params.params, "css", defaultCss);
    },
    // 设置属性，同时添加进全局操作步骤
    setControlItem(e) {
      this.$setWithAction(this.params, "borderType", e);
    },
    // 设置样式
    setStyleType(item) {
      this.$setWithAction(this.params, "styleType", item.value);
      console.log(this.params);
    },
    // 设置搜索框固顶
    setFixedTop(e) {
      this.$setWithAction(this.params, "fixedTop", e);
    },

    setContentAlign(e) {
      this.$set(this.params.params, "contentAlign", e);
    },

    // 重置圆角
    resetSpace(e) {
      let type = e.type;
      console.log(type);
      this.$set(this.params.moduleCss, type, 0);
    },
    // 重置边距
    resetMp() {
      this.$set(this.params.moduleCss, "margin", 0);
      this.$set(this.params.moduleCss, "padding", 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.control-item {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px 14px 24px;
    span {
      font-size: 12px;
      color: #8c8c8c;
    }
    .control-name {
      font-size: 14px;
      font-weight: 600;
      color: #000000;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
  .control-body {
    width: 100%;
    .control-section {
      width: 228px;
      margin: 0 auto;
      text-align: center;
      .control-item {
        width: 100%;
        .control-title {
          padding: 24px 0 14px 0;
          font-size: 12px;
          color: #000000;
          text-align: left;
        }
        .flex-between {
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        .reset {
          font-size: 12px;
          color: #9e9e9e;
          cursor: pointer;
        }
        .control-content {
          .example-list {
            width: 100%;
            display: flex;
            flex-wrap: wrap;
            .example-item {
              width: 70px;
              height: 70px;
              background: #f6f7f9;
              border-radius: 4px;
              margin-right: 9px;
              display: flex;
              justify-content: center;
              align-items: center;
              cursor: pointer;
              overflow: hidden;
              .iconfont {
                font-size: 60px;
              }
            }
            .example-item:last-child {
              margin-right: 0;
            }
            .active {
              border: 2px solid #1890fc;
            }
          }
          .border-select,
          .fixed-top-select {
            width: 100%;
            height: 100%;
            ::v-deep .ant-select-selection--single {
              height: 100%;
              border: 0 none;
              background: #f2f2f2;
            }
            ::v-deep .ant-select-selection__rendered {
              line-height: 40px;
            }
          }
          .keyword-input {
            width: 228px;
            height: 40px;
            background: #f6f7f9;
            border-radius: 4px;
            input {
              height: 100%;
              background-color: #f6f7f9;
              border: 0 none;
            }
          }
        }
      }
    }
  }
}

.com-beauty-item {
  width: 100%;
  padding-bottom: 6px;
  border-bottom: 1px solid #f0f2f5;
  .beauty-item-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0 12px 0;
    font-size: 12px;
    font-weight: 400;
    color: #000000;
    .header-action {
      display: flex;
      align-items: center;
      .iconfont {
        font-size: 18px;
        cursor: pointer;
      }
      .iconfont:first-child {
        margin-right: 5px;
      }
    }
    span {
      cursor: pointer;
      user-select: none;
    }
  }
  .beauty-item-body {
    width: 100%;
    margin-bottom: 12px;
    .border-select {
      width: 98%;
      height: 100%;
      ::v-deep .ant-select-selection--single {
        height: 100%;
        border: 0 none;
        background: #f2f2f2;
      }
      ::v-deep .ant-select-selection__rendered {
        line-height: 40px;
      }
    }
    .color-set {
      width: 100%;
      height: 40px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      input {
        height: 40px;
        background: #f6f7f9;
        border: 0 none;
        border-radius: 4px;
      }

      .ant-input:first-child {
        width: 46px;
        margin-left: 2px;
        padding: 7px 12px;
      }
      .ant-input:last-child {
        width: 170px;
        margin-right: 2px;
      }
    }
  }
}
</style>
